<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>修改厂商</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript" src="<%=path %>/resource/lib/plugins/ajaxfileupload.js"></script>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <div tabid="tabA" title="基本信息" lselected="true">
            <form id="formSet1">
                <div class="fieldset1 tabel_col clearFix">
                    <div class="caption">
                        <span class="title">基本信息</span>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">厂商名称</div>
                        <div class="field">
                            <input name="mfrNm" id="mfrNm" type="text" class="ui-textbox" validate="{required:true}">
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">社会统一信用代码</div>
                        <div class="field">
                            <input name="succ" id="succ" type="text" class="ui-textbox" validate="{required:true}">
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">厂商地址</div>
                        <div class="field">
                            <input name="mfrAddr" id="mfrAddr" type="text" class="ui-textbox" value="">
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">办公电话</div>
                        <div class="field">
                            <input name="mfrTel" id="mfrTel" type="text" class="ui-textbox"  validate="{mobileAndFixedPhone:true}"
                                   value="">
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">区域</div>
                        <div class="field">
                            <!-- <input name="rgnPrCd" id="rgnPrCd" type="text" class="ui-textbox" value=""> -->
                            <jsp:include page="../../system/sysRegion/region.jsp"
                                         flush="true">
                                <jsp:param name="regionShowLvl" value="2" />
                            </jsp:include>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">
                            <span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="说明：厂商金融业务放款时，用于判断放款金额是否扣除贴息费用项。"></span>放款方式
                        </div>
                        <div class="field">
                            <select name="payTypCd" id="payTypCd" data-value=" " validate="{required:true}">
                                <option value=" " checked >请选择</option>
                                <c:forEach items="${payTypCdList }" var="kv">
                                    <option value="${kv.key }">${kv.value }</option>
                                </c:forEach>
                            </select>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="caption">
                        <span class="title">更多信息</span>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">经销品牌(卡车类)</div>
                        <div class="field">
                            <input type="text" id="tkBrCd" name="tkBrCd" ltype="combobox"
                                   validate="{required:false}" />
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">经销品牌(乘用车类)</div>
                        <div class="field">
                            <input type="text" id="carBrCd" name="carBrCd" ltype="combobox"
                                   validate="{required:false}" />
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">经销品牌(客车类)</div>
                        <div class="field">
                            <input type="text" id="busBrCd" name="busBrCd" ltype="combobox"
                                   validate="{required:false}" />
                        </div>
                    </div>
                </div>
                <div class="sqPanel">
                    <div class="sqPanel_head inL">
                        <span>社会关系/家庭成员</span>
                    </div>
                    <div class="sqPanel_body">
                        <div id="ligergrid_A1" class="sq-grid"></div>
                    </div>
                </div>
                <div class="btnsBox">
                    <span id="saveBtn1" onclick="inputReason()" class="sq-button sq-button-round">保存</span>
                </div>
            </form>
        </div>
        <div tabid="tabB" title="资料信息">
            <iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
        </div>
        <div tabid="tabC" title="备案账号">
            <iframe frameborder="0" name="tabC" id="tabC" src=""></iframe>
        </div>
        <div tabid="tabD" title="流程跟踪">
            <iframe frameborder="0" name="tabD" id="tabD" src=""></iframe>
        </div>
        <div tabid="tabE" title="相关项目">
            <iframe frameborder="0" name="tabE" id="tabE" src=""></iframe>
        </div>
        <div tabid="tabF" title="变更记录">
            <iframe frameborder="0" name="tabF" id="tabF" src=""></iframe>
        </div>
    </div>
</div>
<script type="text/javascript">
    var loadedTabs=[];
    var mfrRlPsnGrid;
    var isFlow = '${isFlow}';
    var mfrId = '${mfrId}';
    var modId = '${modId}';
    var isModify = '${isModify}';
    var isMdfPayTyp = '${isMdfPayTyp}';
    var currentOrgCd = '${currentOrgCd}';

    $(function () {

        var _tkBrCdListJSON = ${tkBrCdListJSON};
        $("#tkBrCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
            data: _tkBrCdListJSON,
            valueField: 'key',
            textField:'value'
        });
        var _carBrCdListJSON = ${carBrCdListJSON};
        $("#carBrCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
            data: _carBrCdListJSON,
            valueField: 'key',
            textField:'value'
        });
        var _busBrCdListJSON = ${busBrCdListJSON};
        $("#busBrCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
            data: _busBrCdListJSON,
            valueField: 'key',
            textField:'value'
        });

        $("#formSet1").ligerForm({
            validate : true
        });
        $("#formSet1").ligerForm();

        initTab();
        initData();
        initMfrRlGrid();
        disableFiled();
    });

    /**
     * 数据加载
     */
    function initData(){
        var id = mfrId;
        if(!id){
            return;
        }
        var _url = '<%=path%>/mfr/mfrBscInfo/getById.do';
        if(modId){
            _url = '<%=path%>/product/mfrInfo/getMfrInfoFlowById.do';
        }
        $.ajax({
            type: 'get',
            dataType:'json',
            data:{id:id,modId:modId,currentOrgCd:currentOrgCd,isFlow:isFlow},
            url: _url,
            success:function(msg){
                if(msg.success == 1){
                    setData(msg.data);//设置数据
                }else{
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                }
            }
        });
    }
    //设置页面数据
    function setData(data){
        var form = liger.get("formSet1");

        //区域数据处理
        setRgnProvCdUpdataValue(data.rgnPrCd);
        setRgnCityCdUpdataValue(data.rgnCyCd);
        setRegionSelectDataChange();

        $("#mfrNm").val(data.mfrName);
        $("#succ").val(data.succ);
        $("#mfrAddr").val(data.mfrAddr);
        $("#mfrFax").val(data.mfrFax);
        $("#mfrTel").val(data.mfrTel);
        $("#lmNm").val(data.lmNm);
        $("#lmIdNum").val(data.lmIdNum);
        //$("#lmOfficeTel").val(data.lmOfficeTel);
        $("#lmZipNo").val(data.lmZipNo);
        $("#lmAddr").val(data.lmAddr);
        $("#lmEMail").val(data.lmEMail);
        $("#lmMp1").val(data.lmMp1);
        $("#lmMp2").val(data.lmMp2);
        liger.get("payTypCd").setValue(data.payTypCd);
        liger.get("payTypCd").updateStyle();

        $("#tkBrCd").ligerGetComboBoxManager().selectValue(data.tkBrCdNms);
        $("#tkBrCd").ligerGetComboBoxManager().updateStyle();
        $("#carBrCd").ligerGetComboBoxManager().selectValue(data.carBrCdNms);
        $("#carBrCd").ligerGetComboBoxManager().updateStyle();
        $("#busBrCd").ligerGetComboBoxManager().selectValue(data.busBrCdNms);
        $("#busBrCd").ligerGetComboBoxManager().updateStyle();

    };

    //初始化Tab页
    function initTab(){
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: 450,
            onBeforeSelectTabItem: function (tabid) {
                var _mId = mfrId;
                if(tabid!="tabA"){
                    if(!_mId){
                        top.$.ligerDialog.SQalert({content: "请确认厂商基本信息已存在", SQ_type: "warning"});
                        return false;
                    }
                }
            },
            onAfterSelectTabItem: function(tabid) {
                if (loadedTabs.indexOf(tabid)<0) {
                    var _mId = mfrId;
                    if(tabid!="tabA"){
                        if(!_mId){
                            top.$.ligerDialog.SQalert({content: "请确认厂商基本信息已存在", SQ_type: "warning"});
                            return false;
                        }
                    }
                    loadedTabs.push(tabid);
                    switch (tabid){
                        case "tabB": //厂商资料
                            pageInTab.setTabItemSrc(tabid, "<%=path%>/mfr/mfrBscInfo/toMfrFileAddPage.do?mfrId="+ mfrId);
                            break;
                        case "tabC"://备案账号
                            pageInTab.setTabItemSrc(tabid, "<%=path%>/mfr/mfrbankacc/toListPageDetail.do?isDetail=1&mfrId="+mfrId );
                            break;
                        case "tabD"://流程追踪
                            pageInTab.setTabItemSrc(tabid, "<%=path%>/mfr/mfrBscInfo/toMfrFlowPage.do?mfrId="+mfrId);
                            break;
                        case "tabE"://相关项目
                            pageInTab.setTabItemSrc(tabid, "<%=path%>/product/mfrInfo/toMfrPrjBscInfoDetailList.do?mfrId="+mfrId);
                            break;
                        case "tabF"://变更记录
                            pageInTab.setTabItemSrc(tabid, "<%=path%>/mfr/mfrinfomoddtl/toListPage.do?modId="+ modId);
                            break;
                    }
                };
                SetIframe_height();
            }
        });
    };

    //证件类型
    var certTypCdListJSON = [];
    <c:if test="${not empty certTypCdListJSON}"> certTypCdListJSON = ${certTypCdListJSON}; </c:if>

    //联系人类型
    var rlTypCDListJSON = [];
    <c:if test="${not empty rlTypCDListJSON}"> rlTypCDListJSON = ${rlTypCDListJSON}; </c:if>

    //联系人类型
    var mustAddRlPsnJSON = [];
    <c:if test="${not empty mustAddRlPsnTypCdJSON}">
    mustAddRlPsnJSON = ${mustAddRlPsnTypCdJSON};
    console.log("mustAddRlPsnJSON ==="+JSON.stringify(mustAddRlPsnJSON));
    </c:if>

    //初始化主要人员信息
    function initMfrRlGrid() {
        var _mId = mfrId;
        var _audStsCd = 0;
        if(!_mId){
            return; //验证不通过，不执行以下代码
        }
        $("#ligergrid_A1").ligerGrid({
            usePager: false,
            url: '<%=path%>/mfr/mfrrlpsn/initList.do?mfrId=' +_mId,
            method : 'get',
            columns: [
                { display: '联系人姓名', name: 'rlNm', minWidth: 100},
                { display: '联系人类型', name: 'rlTypCdNm', minWidth: 140},
                { display: '证件类型', name: 'certTypCdNm', minWidth: 140},
                { display: '证件号', name: 'certNo', minWidth: 50, render: function(rowdata, rowindex, value){
                        if (value != null && value != '') {
                            return '<a href="javascript:toCertNoCheckPage(\''+value+'\');" class="sq-button-hasicon link">'
                                + '<i class="sqBtnIco_1"></i></a>'
                                + value;
                        }
                    }},
                { display: '联系电话', name: 'tel', minWidth: 150},
                { display: '备注', name: 'rlRem', minWidth: 150},
                { display: '工商信息校验', name: 'checkVerify', minWidth: 150,
                    render: function(rowdata, rowindex, value){
                        var h = "";
                        if(_audStsCd == 1){
                            if(rowdata.busInfoVerify == 2 || rowdata.busInfoVerify == null){
                                //h += "<a  href = "javascript:checkRlPsn('Verify',\''+rowdata.id+'\',\''+rowdata.rlNm+'\',\''+rowdata.certNo+'\',\''+rowdata.tel+'\');" class = "sq-button sq-button-round">验证</a>"

                                h+= '<a class="sq-button sq-button-round" href="javascript:checkRlPsn(1,\''+rowdata.id+'\',\''+rowdata.rlNm+'\',\''+rowdata.certNo+'\',\''+rowdata.tel+'\',\''+rowdata.rlTypCd+'\');">验证</a>'
                            }else{
                                h +='<div class="sq-button sq-button-round disabled">已校验</div>'
                            }
                        }
                        return h;
                    }
                },
                { display: '工商信息校验结果', name: 'busInfoVerify', minWidth: 150,
                    render: function(rowdata, rowindex, value){
                        if(rowdata.busInfoVerify == 1){
                            return "一致" ;
                        }else if(rowdata.busInfoVerify == -1){
                            return "不一致";
                        }else if(rowdata.busInfoVerify == 0){
                            return "未查得";
                        }else{
                            return "";
                        }
                    }
                },
                { display: '三要素校验（机构1）', name: 'PYCheck', minWidth: 150,
                    render: function(rowdata, rowindex, value){

                        var h = "";
                        if(_audStsCd == 1){
                            if(rowdata.pyPerVerify == 2 || rowdata.pyPerVerify == null){
                                //h += "<a  href = "javascript:checkRlPsn('Verify',\''+rowdata.id+'\',\''+rowdata.rlNm+'\',\''+rowdata.certNo+'\',\''+rowdata.tel+'\');" class = "sq-button sq-button-round">验证</a>"

                                h+= '<a class="sq-button sq-button-round" href="javascript:checkRlPsn(2,\''+rowdata.id+'\',\''+rowdata.rlNm+'\',\''+rowdata.certNo+'\',\''+rowdata.tel+'\',\''+rowdata.rlTypCd+'\');">验证</a>'
                            }else{
                                h+='<div class="sq-button sq-button-round disabled">已校验</div>'
                            }
                        }
                        return h;
                    }
                },
                { display: '三要素校验结果1', name: 'pyPerVerify', minWidth: 150,
                    render: function(rowdata, rowindex, value){
                        if(rowdata.pyPerVerify == 1){
                            return "一致" ;
                        }else if(rowdata.pyPerVerify == -1){
                            return "不一致";
                        }else if(rowdata.pyPerVerify == 0){
                            return "未查得";
                        }else{
                            return "";
                        }
                    }
                },
                { display: '三要素校验（机构2）', name: 'TDCheck', minWidth: 150,
                    render: function(rowdata, rowindex, value){
                        var h = "";
                        if(_audStsCd == 1){
                            if(rowdata.tdPerVerify == 2 ||  rowdata.tdPerVerify == null){
                                //h += "<a  href = "javascript:checkRlPsn('Verify',\''+rowdata.id+'\',\''+rowdata.rlNm+'\',\''+rowdata.certNo+'\',\''+rowdata.tel+'\');" class = "sq-button sq-button-round">验证</a>"

                                h+= '<a class="sq-button sq-button-round" href="javascript:checkRlPsn(3,\''+rowdata.id+'\',\''+rowdata.rlNm+'\',\''+rowdata.certNo+'\',\''+rowdata.tel+'\',\''+rowdata.rlTypCd+'\');">验证</a>'
                            }else{
                                h +='<div class="sq-button sq-button-round disabled">已校验</div>'
                            }
                        }
                        return h;
                    }
                },
                { display: '三要素校验结果2', name: 'tdPerVerify', minWidth: 150,
                    render: function(rowdata, rowindex, value){
                        if(rowdata.tdPerVerify == 1){
                            return "一致" ;
                        }else if(rowdata.tdPerVerify == -1){
                            return "不一致";
                        }else if(rowdata.tdPerVerify == 0){
                            return "未查得";
                        }else{
                            return "";
                        }
                    }
                },
                { display: '三要素校验（机构3）', name: 'BRCheck', minWidth: 150,
                    render: function(rowdata, rowindex, value){
                        var h = "";
                        if(_audStsCd == 1){
                            if(rowdata.brPerVerify == 2 || rowdata.brPerVerify == null){
                                //h += "<a  href = "javascript:checkRlPsn('Verify',\''+rowdata.id+'\',\''+rowdata.rlNm+'\',\''+rowdata.certNo+'\',\''+rowdata.tel+'\');" class = "sq-button sq-button-round">验证</a>"
                                h+= '<a class="sq-button sq-button-round" href="javascript:checkRlPsn(4,\''+rowdata.id+'\',\''+rowdata.rlNm+'\',\''+rowdata.certNo+'\',\''+rowdata.tel+'\',\''+rowdata.rlTypCd+'\');">验证</a>'
                            }else{
                                h +='<input class="sq-button sq-button-round disabled" type="button" value="已校验" disabled>'
                            }
                        }
                        return h;
                    }
                },
                { display: '三要素校验结果3', name: 'brPerVerify', minWidth: 150,
                    render: function(rowdata, rowindex, value){
                        if(rowdata.brPerVerify == 1){
                            return "一致" ;
                        }else if(rowdata.brPerVerify == -1){
                            return "不一致";
                        }else if(rowdata.brPerVerify == 0){
                            return "未查得";
                        }else{
                            return "";
                        }
                    }
                },

            ],
            pageSize:10,
            root:'rows',
            record:'total',
            hideLoadButton : true,
            width: '100%',
            isScroll: false,
            //checkbox:true,
            rownumbers:true,
            onAfterShowData: function() {
                SetIframe_height ();
            }
        });
        mfrRlPsnGrid = liger.get("ligergrid_A1");
    };

    function inputReason(){
        var form = new liger.get("formSet1");
        if (StringUtils.isEmpty($('#payTypCd').val())) {
            $.ligerDialog.SQalert({content: "请选择放款方式" , SQ_type: "warning" });
            return false; //验证不通过，不执行以下代码
        }
        var data = form.getData();
        var id = mfrId;
        data["id"]= id;
        data["modId"]= modId;
        data["isBsc"]= isModify;
        data["currentOrgCd"] = currentOrgCd;
        data["rgnPrCd"] = getRgnProvCd();//获取省代码
        data["rgnCyCd"] = getRgnCityCd();//获取市代码
        data["payTypCdNm"] = $('#payTypCd option:checked').text();
        var mfrRlPsnList = mfrRlPsnGrid.getData();
        data["mfrRlPsnList"] = JSON.stringify(mfrRlPsnList);

        checkChangelowMfrInfo(data);

    }

    function checkChangelowMfrInfo(data) {
        $.ligerDialog.SQalert({content: "判断是否变更" , SQ_type: "warning" });
        var url = '<%=path%>/product/mfrInfo/checkChangeMfrInfo.do';
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    if (msg.info == 1) {
                        startMfrAdmissionFlow();
                    } else {
                        saveMfrInfo('');
                    }
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //发起审核流程
    function startMfrAdmissionFlow() {
        var modelTyp = '046';//流程业务分类-
        if (StringUtils.isEmpty(modelTyp)) {
            return;
        }
        var flowDialog = $.ligerDialog.SQopen({
            url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp=' + modelTyp,
            width: 700,
            height: 400,
            title: '请选择要发起的流程',
            buttons: [{
                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
                onclick: function (item, Dialog) {
                    if (Dialog.onOk) {
                        $.ligerDialog.SQconfirm('是否确定发起变更流程?', function (flag) {
                            if (flag == false) {
                                return;
                            } else {
                                Dialog.onOk();
                            }
                        })
                    }
                }
            }, {
                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }
            ],
            onClose: function () {
                var json = flowDialog._DATA;
                if (!json) {
                    return;
                }
                saveMfrInfo(json);
            }
        });
    }

    function saveMfrInfo(json) {
        var form = new liger.get("formSet1");
        if (!form.valid()) {
            $.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
        if (StringUtils.isEmpty($('#payTypCd').val())) {
            $.ligerDialog.SQalert({content: "请选择放款方式" , SQ_type: "warning" });
            return false; //验证不通过，不执行以下代码
        }

        var data = form.getData();
        data["isFlow"] = isFlow ;
        var id = mfrId;
        data["id"]= id;
        data["modId"]= modId;
        data["currentOrgCd"] = currentOrgCd;
        data["rgnPrCd"] = getRgnProvCd();//获取省代码
        data["rgnCyCd"] = getRgnCityCd();//获取市代码
        data["payTypCdNm"] = $('#payTypCd option:checked').text();
        if (StringUtils.isNotEmpty(json)) {
            data["procDefKey"] = json.procDefKey;
            data["procDefId"] = json.procDefId;
            data["procNo"] = json.procNo;
        }
        var mfrRlPsnList = mfrRlPsnGrid.getData();
        data["mfrRlPsnList"] = JSON.stringify(mfrRlPsnList);
        var url='<%=path%>/product/mfrInfo/modifyMfrInfoStartFlow.do';
        if(modId){
            url='<%=path%>/product/mfrInfo/modifyMfrAgain.do';
        }
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType:'json',
            data:data,
            url: url,
            beforeSend: function(){
                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
            },
            success:function(msg){
                wait_dialog.close();
                if(msg.success == 1){
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                    if(msg.data){
                        $("#mId").val(msg.data);
                    }
                    //callback回调
                    var TAB=top.mainApp.parentTab;
                    var currentTabid=TAB.getSelectedTabItemID();
                    var currentTabiframe=top.$("#"+currentTabid).get(0);
                    var callback=currentTabiframe.W2W.callback;
                    callback();
                }else{
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                }
            }
        })
    }

    function disableFiled() {

        if (liger.get("mfrNm")) {
            liger.get("mfrNm").setDisabled(true);
        }
        if (liger.get("succ")) {
            liger.get("succ").setDisabled(true);
        }
        if (liger.get("mfrAddr")) {
            liger.get("mfrAddr").setDisabled(true);
        }
        if (liger.get("mfrTel")) {
            liger.get("mfrTel").setDisabled(true);
        }
        //禁用省市
        disabledRgnProvCd();
        disabledRgnCityCd();
        if (liger.get("tkBrCd")) {
            liger.get("tkBrCd").setReadonly(true);
        }
        if (liger.get("carBrCd")) {
            liger.get("carBrCd").setReadonly(true);
        }
        if (liger.get("busBrCd")) {
            liger.get("busBrCd").setReadonly(true);
        }
    }

</script>
</body>
</html>